package game.sb;

import com.bit.catmoney.CMusic;
import com.bit.catmoney.ExplainActivity;
import com.bit.catmoney.MainActivity;
import com.bit.catmoney.OptActivity;
import com.bit.catmoney.R;
import com.bit.catmoney.RankActivity;
import com.bit.catmoney.ReadyActivity;

import game.sb.CatMoneyGame.OnGameOverListener;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class CatMoney extends Activity implements OnGameOverListener {

	private View view;
	private CatMoneyGame CatMoneyrGame;
	CMusic myMusic;

	AlertDialog.Builder dialogBuilder;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		LayoutInflater factory = LayoutInflater.from(this);

		// ���� ���� �ƿ��� �����Ѵ�.
		view = factory.inflate(R.layout.main, null);
		setContentView(view);


		CatMoneyrGame = (CatMoneyGame) this.findViewById(R.id.ll_absolute);
		CatMoneyrGame.setOnGameOverListener(this);

		// Ű �Է��� �޾Ƶ��δ�.
		view.setFocusable(true);
		view.setFocusableInTouchMode(true);

	}

	public void onGameOvered(View sender, long score) {
		// TODO Auto-generated method stub
		
		Intent intent = new Intent(CatMoney.this, ScoreActivity.class);
		intent.putExtra("Score", score + "");
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
		finish();
	}

	@Override
	protected void onStop() {
		super.onStop();
		((ArcadeGame) view).halt();
	}

	@Override
	protected void onPause() {
		super.onPause();
		onStop();
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		((ArcadeGame) view).resume();
	}

	public void onBackPressed() {
		CatMoneyGame.mMode = CatMoneyGame.PAUSE;
		dialogBuilder = new AlertDialog.Builder(this);
		dialogBuilder.setTitle("��Ӱ����� �����Ͻðڽ��ϱ�?");

		dialogBuilder.setPositiveButton("Yes", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub

				CatMoneyGame.mMode = CatMoneyGame.RUN;
			}
		});

		dialogBuilder.setNegativeButton("No", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				CatMoneyrGame.GameOver();
				CatMoneyGame.mMode = CatMoneyGame.RUN;
			}
		});
		dialogBuilder.show();
		// if(){
		// Intent intent = new Intent(CatMoney.this, MainActivity.class);
		// startActivity(intent);
		// }

	}
}
